grammar hetno;

options{  
  output=AST;
  language=CSharp3;
//  language=Java;
  ASTLabelType=CommonTree;  
}

tokens{    
//  NP;
  VP; 
  Cau; 
  Np;
  Vp;
  WS;
  Verb;
  
  CauDon;
  CauPhuc;
  ChuNgu;
  ViNgu;
  TrangNgu;
  
  NP;
  AP;
  Nc;
  N;
  V;
  C;
  A;
  VP;
  E;
  PP;
  I;
  R;
  M;
  Nu;
  P;
}

@lexer::namespace { antlr_truyencuoihetno }
@parser::namespace { antlr_truyencuoihetno }

@header {
   using System; 
   using System.Collections;
}

public prog : caudon | cauPhuc  ;

caudon	:	chuNgu viNgu End_sentence -> ^(CauDon chuNgu viNgu)
	| trangNgu chuNgu viNgu ThanTu End_sentence -> ^(CauDon trangNgu chuNgu viNgu ^(I ThanTu))
//	| chuNgu viNgu trangNgu ThanTu End_sentence -> ^(CauDon  chuNgu viNgu trangNgu ^(I ThanTu))
		;
cauPhuc	:	Conjuction np? vp Conjuction chuNgu viNgu -> ^(CauPhuc ^(C Conjuction) np? vp ^(C Conjuction)   chuNgu viNgu )
	
;


chuNgu	:	//Noun Pronoun -> ^(ChuNgu ^(N Noun) ^(P Pronoun))
	|	NounCategory? Pronoun ->^(ChuNgu ^(Nc NounCategory)? ^(P Pronoun))
	|	Noun -> ^(ChuNgu ^(N Noun))
	|	np -> ^(ChuNgu np)
	;
viNgu	:	vp -> ^(ViNgu vp)
	|	Verb -> ^(ViNgu ^(V Verb))
	|	ap -> ^(ViNgu ap)
;

trangNgu:	Noun Pronoun -> ^(TrangNgu ^(N Noun) ^(P Pronoun));
//cau1	:	np (COMMA?) vp End_sentence? -> ^(Cau np vp );


vp	: Verb vp pp -> ^(VP ^(V Verb) vp pp)
	| Verb Noun -> ^(VP ^(V Verb) ^(N Noun))
	| Verb Adverb np -> ^(VP ^(V Verb) ^(R Adverb) np) 
	| Verb np vp  Adverb? -> ^(VP ^(V Verb) np vp ^(R Adverb))
	;
pp	:	Preposition  vp -> ^(PP ^(E Preposition) vp);
np	:	NounCategory? Noun Adjective -> ^(NP ^(Nc NounCategory) ^(N Noun) ^(A Adjective))
//	|	NounCategory Pronoun -> ^(NP ^(Nc NounCategory) ^(P Pronoun))
	|	Numeric NounUnit -> ^(NP ^(M Numeric) ^(Nu NounUnit))
	|	Numeric Noun -> ^(NP ^(M Numeric) ^(N Noun))

	;
ap	:	Adjective np? -> ^(AP ^(A Adjective) np) ;
NounCategory	:	'bà';
Noun	:	'vợ' | 'biển' | 'cân' | 'đợt' | 'chồng' | 'nợ' | 'abc';
Adjective	:	'to béo' | 'nặng';
Verb	:	'đi' | 'tắm' | 'giảm' | 'nhẩm tính' | 'hết' | 'còn';
ThanTu	:	'đấy';
Preposition	:	'để';
Pronoun	:	'này' | 'tôi' | 'ta' | 'mình' ;
Adverb	:	'được' | 'nữa';
Numeric	:	'0'..'9'+;
NounUnit:	'ký';
Conjuction
	:	'như vậy' | 'thì';

//WS: (' ' | '\n' | '\t')+ {Skip();};//{$channel = Hidden;};
WS	: (' ' | '\n' | '\t')+ {$channel = Hidden;};
COMMA	:	',' {$channel = Hidden;};
BACHAM	:	'...' {$channel = Hidden;};
End_sentence
	:	'.' | '!' | ':';
